package com.useeinfo.oa.modules.maintaining.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.data.QueryParam;
import com.useeinfo.oa.modules.maintaining.dao.ApplicationScenariosDao;
import com.useeinfo.oa.modules.maintaining.entity.ApplicationScenarios;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplicationScenariosBiz extends CrudBiz<ApplicationScenariosDao, ApplicationScenarios> {

    public Boolean existName(ApplicationScenarios applicationScenarios, Long enterpriseId) {
        if (StringUtils.isBlank(applicationScenarios.getName())) {
            return true;
        }
        QueryParam queryParam = new QueryParam();
        queryParam.getSqlMap().put("enterpriseId", enterpriseId+"");
        queryParam.getSqlMap().put("name", applicationScenarios.getName());
        List<ApplicationScenarios> applicationScenariosList = this.findList(queryParam);

        if (applicationScenarios.getId() == null) {
            return CollectionUtils.isNotEmpty(applicationScenariosList);
        } else {
            return (!((applicationScenariosList.size() == 1 && applicationScenariosList.get(0).getId().equals(applicationScenarios.getId())) || applicationScenariosList.size() == 0));
        }
    }
}
